package com.kbt.listener;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.kbt.util.data.StaticData;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhgk
 * @package: com.kbt.listener
 * @TODO: Activity打开Activty并接收结果
 * @data: 2015/8/15 16:31
 * @version: V1.0
 */
public class ClickActStartActForResultListener implements View.OnClickListener {
    private Class target;
    private int request_code;
    private Map<String, Object> params;
    private Activity activity;


    public ClickActStartActForResultListener(Activity activity, Class _target, int _requst_code, Map params) {
        this.activity = activity;
        this.target = _target;
        this.request_code = _requst_code;
        //参数为空时新建
        this.params = params != null ? params : new HashMap<String, Object>();
    }

    /*********
     * 点击按钮打开Activity
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(v.getContext(), target);
        Bundle bl = new Bundle();
        //处理参数

        for (Map.Entry<String, Object> entry : params.entrySet()) {
            bl.putSerializable(entry.getKey(), (Serializable) entry.getValue());
        }
        intent.putExtra(StaticData.ORDER_TYPE,request_code+"");
        intent.putExtra("bundle", bl);
        activity.startActivityForResult(intent, request_code);

    }
}
